﻿using FluentValidation;
using Portal.Core;
using Portal.Presentation.Models;

namespace Portal.Presentation.Validators
{
	public class UserInfoDataModelValidator : AbstractValidator<UserInfoDataModel>
	{
		public UserInfoDataModelValidator()
		{
			RuleFor(x => x.FirstName)
				.NotEmpty()
				.Length(0, 50);
			
			RuleFor(x => x.LastName)
				.NotEmpty()
				.Length(0, 50);

			var phoneRegEx = RegularExpressions.POLISH_MOBILE_PHONE_NUMBER + "|" + RegularExpressions.POLISH_STATIONARY_PHONE_NUMBER;

			RuleFor(x => x.PrimaryPhone)
				.NotEmpty()
				.Matches(phoneRegEx);

			RuleFor(x => x.SecondaryPhone)
				.Matches(phoneRegEx);

			RuleFor(x => x.PrimaryEmail)
				.NotEmpty()
				.EmailAddress();

			RuleFor(x => x.SecondaryEmail)
				.EmailAddress();
		}
	}
}